package org.test.IO.location_location;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class FileOperation {

	/**
	 * 
	 * @param resourcePath
	 * @param targetPath
	 */
	public void copy(String resourcePath, String targetPath) {
		BufferedReader bufferedReader = null;
		BufferedWriter bufferedWriter = null;
		PrintWriter out = null;// 处理流
		try {
			// 文件->对象
			bufferedReader = new BufferedReader(new FileReader(resourcePath));
			// 文件->对象
			bufferedWriter = new BufferedWriter(new FileWriter(targetPath));
			// 将bufferedWriter封装成打印流
			out = new PrintWriter(bufferedWriter);
			
			String s =null;
			
			while((s=bufferedReader.readLine())!=null){
				out.println(s);//这种写和下面那种都行
//				bufferedWriter.write(s);
				System.out.println(s);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			
			out.close();
			try {
				bufferedReader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
}
